﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace iEN
{
    public partial class Test : System.Web.UI.Page
    {
        DataAccess.DBAccess_CHTD obj = new DataAccess.DBAccess_CHTD();

        protected void Page_Load(object sender, EventArgs e)
        {         
                       
        }

        private void SetReportViewer()
        {
            DataTable dt = new DataTable();
            dt = obj.GetDemandReport("6", new DateTime(2011, 7, 11, 0, 0, 0), new DateTime(2011, 7, 11, 23, 59, 59));
            ReportViewer1.Reset();
            ReportViewer1.LocalReport.ReportPath = obj.OutputRDLC(dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.SetParameters(QueryReportParameter("2010/11/11", "scent", "scent", "100", "100", "scnet"));

            #region 寫法１
            //DataSet ds = new DataSet();
            //ds.Tables.Add(dt);
            //ReportDataSource rds = new ReportDataSource();
            //rds.Name = "DataSet_Data";
            //rds.Value = dt;
            //ReportViewer1.LocalReport.DataSources.Add(rds);
            #endregion

            #region 寫法2
            ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet_Data", dt));
            #endregion
            ReportViewer1.Visible = true;
            ReportViewer1.LocalReport.Refresh();
            
        }

        private ReportParameter[] QueryReportParameter(string sDate, string sReportName, string sRoom, string sTotalPower, string sTotalMoney, string sColumnName)
        {
            ReportParameter[] ReportParameter = new ReportParameter[6];
            ReportParameter[0] = new ReportParameter("Report_Parameter_Date", sDate);
            ReportParameter[1] = new ReportParameter("Report_Parameter_ReportName", sReportName);
            ReportParameter[2] = new ReportParameter("Report_Parameter_Room", sRoom);
            ReportParameter[3] = new ReportParameter("Report_Parameter_TotalPower", sTotalPower);
            ReportParameter[4] = new ReportParameter("Report_Parameter_TotalMoney", sTotalMoney);
            ReportParameter[5] = new ReportParameter("Report_Parameter_Column", sColumnName);
            return ReportParameter;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SetReportViewer();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            #region 驗證GetPowerMeterWithDemand
            GridView1.DataSource = obj.GetPowerMeterWithDemand(30);
            GridView1.DataBind();
            #endregion
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            #region 驗證GetDemandReport
            GridView2.DataSource = obj.GetDemandReport("6", new DateTime(2011, 7, 11, 0, 0, 0), new DateTime(2011, 7, 11, 23, 59, 59));
            GridView2.DataBind();
            #endregion

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            GridView3.DataSource = obj.GetGroupInformation();
            GridView3.DataBind();
        }
    }
}